/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.events.EventBroadcaster;
import com.bourre.events.FrontController;
import com.bourre.events.IEvent;

import fever.utils.Stringifier;

/**
 * Front controller implementation for remoting events / commands.
 * 
 * <p>For example, if you use the <strong>AsWing</strong> UI Framework and the 
 * {@code FvRemoteLoginDialog}, 2 commands are registred in the 
 * {@link RemotingEventController} : 
 * <ul>
 *   <li>FvAMFErrorCommand</li>
 *   <li>FvSessionErrorCommand</li>
 * </ul>
 * 
 * <p>Example
 * {@code
 *   RemotingEventController.getInstance().push( 
 *   	RemotingEventList.AMF_ERROR, FvAMFErrorCommand.getInstance() 
 *   );
 *   
 *   RemotingEventController.getInstance().push( 
 *   	RemotingEventList.SESSION_EXPIRED, FvSessionErrorCommand.getInstance() 
 *   );
 * }
 * 
 * <p>{@link RemotingEventController} is just a central place to put your 
 * event / command pair when working with remoting API.<br />
 * Some basic remoting events are declared in {@link fever.remoting.RemotingEventList}
 * 
 * <p>Take a look at <strong>Pixlib Front Controller API</strong> for more 
 * informations.
 * 
 * @see fever.remoting.RemotingEventList
 * 
 * @author Romain Ecarnot
 */
class fever.remoting.RemotingEventController extends FrontController
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
		
	private static var _instance : RemotingEventController;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	* @return {@link RemotingEventController} instance.
	*/
	public static function getInstance() : RemotingEventController 
	{
		if ( !_instance ) _instance = new RemotingEventController();
		return _instance;
	}
	
	/**
	 * Broadcasts passed-in event
	 * <br />Executes registred command.
	 */
	public function broadcastEvent( event : IEvent ) : Void
	{
		_oEB.broadcastEvent( event );	
	}
	
	/**
	 * Returns string representation.
	 */
	public function toString() : String
	{
		return Stringifier.parse( this );
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	private function RemotingEventController()
	{
		super( new EventBroadcaster( this ) );
	}
 }